import os
from zhipuai import ZhipuAI
from dotenv import load_dotenv, find_dotenv
from langchain_community.embeddings import ZhipuAIEmbeddings


_ = load_dotenv(find_dotenv())

def zhipu_embedding_normal(api_key,embedd_model,text: str):

    client = ZhipuAI(api_key=api_key)
    response = client.embeddings.create(
        model=embedd_model,
        input=text,
    )
    return response


def embedding_langchain(api_key,embedd_model):
    embeddings = ZhipuAIEmbeddings(
        model=embedd_model,
        api_key = api_key
    )
    return embeddings

if __name__ =='__main__':
    api_key = os.environ['ZHIPUAI_API_KEY']
    embedding_model = 'Embedding-2'
    input_text = "The meaning of life is 42"
    embeddings = embedding_langchain(api_key=api_key,embedd_model=embedding_model)